package com.lvhx.springboot.partitioner;

import com.google.common.base.Preconditions;
import com.lvhx.springboot.springbatch.base.DataProvider;
import com.lvhx.springboot.springbatch.base.Parameters;

import java.util.List;

/**
 * DataProvider装饰器, 在执行目标对象之前执行其他的额外操作
 */
public class DataProviderDecorator<T> implements DataProvider<T> {
    private DataProvider<T> provider;

    public DataProviderDecorator(DataProvider<T> dataProvider) {
        Preconditions.checkNotNull(dataProvider, "provider不能为null");

        this.provider = dataProvider;
    }

    @Override
    public List<T> getData(Parameters args) {
        // 将参数中的生效日期放到缓存中
//        Date effDate = args.getDate(JobParameterKey.EFFECTIVE_DATE);
//        CurrentUnitOfWork.getCache().put(DataMapKey.POST_DATE, effDate);
        return provider.getData(args);
    }

}
